# /usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 11:40
# @Author  : lt
# @Email   : lt@163.com
# @File    : kehu_page.py
# @Software: PyCharm
from selenium.webdriver.common.by import By
from page.KHGL_page.Base_Page import BasePage
from time import sleep
class KeHu_page(BasePage):
    # 定位新建客户按钮
    add_kehu_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(1) > div > a')
    #定位客户控件按钮
    kehu_locator = (By.LINK_TEXT, '客户')
    # 定位客户关怀按钮
    kehu_guanhuai_locator = (By.CSS_SELECTOR, 'body > div.container > div.page-header > ul > li:nth-child(4) > a')
    # 定位联系人按钮
    lianxiren_button_locator = (By.CSS_SELECTOR, 'body > div.container > div.page-header > ul > li:nth-child(3) > a')
    # 定位客户池按钮
    kehuchi_anniu = (By.LINK_TEXT, '客户池')
    # 定位所有客户的表
    tobdy_kehu_locator = (By.CSS_SELECTOR, '#form1 > table > tbody')
    # 定位回收站按钮
    huishouzhan_locator = (By.LINK_TEXT, '回收站')
    # 定位回收站的表
    tobdy_huishou_locator = (By.XPATH, '//*[@id="form1"]/table/tbody')
    # 定位删除按钮
    piliangcaozuo_locator = (By.XPATH, '/html/body/div[5]/div[2]/div[1]/ul/div/a')

    # 点击联系人按钮
    def lianxiren_button(self):
        self.driver.find_element(*self.lianxiren_button_locator).click()
    # 点击新建客户关怀
    def add_kehu_guanhuai(self):
        self.driver.find_element(*self.kehu_guanhuai_locator).click()

    # 点击新建客户
    def add_kehu(self):
        self.driver.find_element(*self.add_kehu_locator).click()

    # 点击客户池按钮
    def kehuchhi_click(self):
        self.driver.find_element(*self.kehuchi_anniu).click()
        sleep(3)
    def shanchu(self,kenu_name):
        kehu_tobdy = self.driver.find_element(*self.tobdy_kehu_locator)
        trs1 = kehu_tobdy.find_elements(By.TAG_NAME, 'tr')
        for e in trs1:
            tds1 = e.find_elements(By.TAG_NAME, 'td')
            if tds1[1].text == kenu_name:
                tds1[0].find_element(By.CSS_SELECTOR, 'input[name="customer_id[]"]').click()
        sleep(3)
    def piliang_click(self):
        self.driver.find_element(*self.piliangcaozuo_locator).click()
        sleep(2)
    def shanchupiliang(self):
        self.driver.find_element(By.ID, 'delete').click()
        sleep(2)
        self.driver.switch_to.alert.accept()
        # 点击客户按钮
    def kehu_button(self):
        self.driver.find_element(*self.kehu_locator).click()
    # 点击回收站
    def huishou_click(self):
        self.driver.find_element(*self.huishouzhan_locator).click()
    def qingkong(self,kenu_name):
        tobdy_huishou = self.driver.find_element(*self.tobdy_huishou_locator)
        trs2 = tobdy_huishou.find_elements(By.TAG_NAME, 'tr')
        for j in trs2:
            tds2 = j.find_elements(By.TAG_NAME, 'td')
            if tds2[1].text == kenu_name:
                tds2[0].find_element(By.CSS_SELECTOR, 'input[name="customer_id[]"]').click()
    def piliang_buttton(self):
        self.driver.find_element(*self.piliangcaozuo_locator).click()
        sleep(2)
    def piliang_shanchu(self):
        self.driver.find_element(By.ID, 'delete').click()
        sleep(2)
        self.driver.switch_to.alert.accept()